#include "StdAfx.h"
#include "WEClock.h"
#include "WceUiLoadBitmap.h"
#include "WceUiBgItem.h"
#include "WceUi32Bitmap.h"
#include "WceUiDlg.h"

#define CLOCK_TIMER_ID 1
#define CLOCK_TIMER_LEN 1000

CWEClock::CWEClock(void)
{
}

CWEClock::~CWEClock(void)
{
}

void CWEClock::OnInitLayer()
{
	SetTimer(CLOCK_TIMER_ID, CLOCK_TIMER_LEN);
	OnTimer(CLOCK_TIMER_ID);

	EnableHMove(TRUE);
	EnableVMove(TRUE);

	CRect rc;
	GetClientRect(&rc);
	SetHLimit(0, WceUiGetScreenWidth() - rc.Width());
	SetVLimit(0, WceUiGetScreenHeight() - rc.Height());
	
}

void CWEClock::OnTimer(WORD wIDEvent)
{
	if (wIDEvent == CLOCK_TIMER_ID)
	{
		SYSTEMTIME st;
		GetLocalTime(&st);

		TCHAR szText[32] = {0};

		_stprintf(szText,_T("%02d:%02d:%02d"),
			st.wHour,
			st.wMinute,
			st.wSecond
			);
		SetText(szText);
	}
}
void CWEClock::OnLButtonDown(UINT nFlags, POINT point)
{
	CWceUiLayer *pDeskTop = GetDlg()->GetChildByName(L"desktop");
	MoveBefore(pDeskTop);
	CWEMoveAbleStatic::OnLButtonDown(nFlags, point);
}